.text
main:		
	movei $sp, 0x1F
	movei $a0, 0x7

	jal Fib
	halt


Fib:	//$a0 = int n

C0:
	//slti 	$t0, $A0, 0x0					// if ( n < 0) then $t0 = 1
	//beq 	$t0,$zero, C1					// if ( $t0 == 0) then (n >= 0) so branch C1
	setBEQ 0x0, C1	
											// 0x3DEADBEEF = 0b01111011110101011011011111011101111	
	liu		0x7B, 0x1		
	liu		0x1AB, 0x0		//$t0, 0xDEAD
	lil		0xDF, 0x1		
	lil		0xEF, 0x0		//$t0, 0xBEEF
											
	move 	$v0, $t0				// still in C0; return 0x3DEADBEEF
	
	j Pop
	
C1:
	//slti 	$t0, $a0, 0x3 					// if ( n < 3) then $t0 = 1
	//beq 	$t0, 0x0, C2					// if ($t0 ==0) then ( n >2 ) branch to C2
	setBEQ 0x3, C2
	
	movei 	$v0, 0x1					// still in C1; return 1
   
	j Pop

C2:	
	movBNE	0x1D, C3							// if (n != 29) branch to C3

	liu		0x00	, 0x1									// 514229 = 0x7D8B5 = 0b1111101100010110101	
	liu		0x01, 0x0
	lil		0x1EC, 0x1
	lil     0xB5, 0x0

	move 	$v0, $t0					// return 514229
   
	j Pop
	
C3:	
	movBNE 0x1E, C4							// if (n != 30) branch to C4
	
	liu		0x00, 0x1						// 832030 = 0xCB21E = 0b11001011001000011110
	liu 	0x03, 0x0
	lil 	0x59, 0x1
	lil		0x1E, 0x0
	
	move 	$v0, $t0					// return 832030
   
	j Pop

C4:
	movBNE 0x30, C5							// if (n != 48) branch to C5
	
									// 4807526976 = 0x11E8D0A40 = 0b100011110100011010000101001000000
	liu		0x23, 0x1		
	liu		0x1A3, 0x0		
	lil		0x85, 0x1		
	lil		0x40, 0x0	
	
	move 	$v0, $t0			// return 4807526976
   
	j Pop
	
C5:
	movBNE 0x31, Else							// if (n != 49) branch to C6
											
									// 7778742049 = 0x1CFA62F21 = 0b111001111101001100010111100100001
	liu		0x39, 0x1		
	liu		0x1E9, 0x0
	lil		0x117, 0x1		
	lil		0x121, 0x0
	
	move 	$v0, $t0			// return 7778742049
   
Pop:
	jr   $ra                       			//return to caller

Else:	
	addi 	$sp, 0x3D					// adjust stack to make room for 3 items ($ra, n, and result)
	sw 		$ra, 0($sp)						// save return address
	sw		$a0, 1($sp)						// save register $a0 for n

	addi 	$a0, 0x3F					//  	$a0 = n = n - 1 (reassign n = n-1 and simultaneously do samet
											//					 thing with $a0)
	jal		Fib
	sw 		$v0, 2($sp)							// v0 = Fib(n-1) 
	
	lw		$a0, 1($sp)						// return for jal, restore argument n
	
	addi	$a0, 0x3E					//	$a0 = n - 2 	(use $t1 to temporarily hold n-2)
	jal		Fib
	
	
	lw		$t4, 2($sp)						// 	$t4 = fib(n-1)
	add 	$v0, $t4						// 	$v0 = $t4 + $v0 
	lw 		$ra, 0($sp)
	
	addi 	$sp, 0x3
	jr 		$ra								// return to caller 


//53 lines total
